package cn.gson.boot.controller;

import cn.gson.boot.model.pojos.*;
import cn.gson.boot.model.service.KeFuService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/kefu")
public class KeFuController {
    @Autowired
    KeFuService keFuService;

    //新增客服
    @RequestMapping("/addKeFu")
    @ResponseBody
    public void addKeFu(@RequestBody Kefu kefu){
        keFuService.addKeFu(kefu);
    }

    //查询客服所有客服
    @RequestMapping("/selectAllKeFu")
    @ResponseBody
    public Map<String,Object> selectAllKeFu(String kName, Integer pageNumm, Integer pageSizee){
        Page<Object> objects = PageHelper.startPage(pageNumm, pageSizee);
        List<Kefu> list = keFuService.selectAllKeFu(kName);

        Map<String,Object> map = new HashMap();
        map.put("total", objects.getTotal());
        map.put("list", list);
        return map;
    }

    //移除客服
    @RequestMapping("/yichuKeFu")
    @ResponseBody
    public void yichuKeFu(Integer kfId){
       keFuService.yichuKeFu(kfId);
    }
}
